<%--
  Created by IntelliJ IDEA.
  User: feng
  Date: 2023/5/14
  Time: 9:17
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
  <!-- 页面meta -->
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title>体育馆管理系统</title>
  <meta name="description" content="体育馆管理系统">
  <meta name="keywords" content="体育馆管理系统">
  <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
  <!-- 引入样式 -->
  <link rel="stylesheet" href="<%=request.getContextPath()%>/resources/plugins/elementui/index.css">
  <link rel="stylesheet" href=".<%=request.getContextPath()%>/resources/plugins/font-awesome/css/font-awesome.min.css">
  <link rel="stylesheet" href="<%=request.getContextPath()%>/resources/css/style.css">
  <!-- 引入组件库 -->
  <script type="text/javascript" src="<%=request.getContextPath()%>/resources/js/jquery.min.js"></script>
  <script src="<%=request.getContextPath()%>/resources/js/vue.js"></script>
  <script src="<%=request.getContextPath()%>/resources/plugins/elementui/index.js"></script>
  <script src="<%=request.getContextPath()%>/resources/js/axios-0.18.0.js"></script>

  <link rel="stylesheet" href="<%=request.getContextPath()%>/resources/css/page-health-login.css" />
  <link rel="stylesheet" href="<%=request.getContextPath()%>/resources/plugins2/elementui/index.css" />
  <script src="<%=request.getContextPath()%>/resources/plugins2/jquery/dist/jquery.min.js"></script>
  <script src="<%=request.getContextPath()%>/resources/plugins2/healthmobile.js"></script>
  <script src="<%=request.getContextPath()%>/resources/plugins2/vue/vue.js"></script>
  <script src="<%=request.getContextPath()%>/resources/plugins2/vue/axios-0.18.0.js"></script>
  <script src="<%=request.getContextPath()%>/resources/plugins2/elementui/index.js"></script>
  <style>
    .datatable {
      position: relative;
      box-sizing: border-box;
      -webkit-box-flex: 1;
      width: 100%;
      max-width: 100%;
      font-size: 14px;
      color: rgb(96, 98, 102);
      overflow: hidden;
      flex: 1 1 0%;
    }
    .datatable td, .datatable th {
      padding: 12px 0;
      min-width: 0;
      -webkit-box-sizing: border-box;
      box-sizing: border-box;
      text-overflow: ellipsis;
      vertical-align: middle;
      position: relative;
      text-align: left;
    }
  </style>
</head>
<body class="hold-transition">
<div id="app">
  <div class="content-header">
    <h1>器材预约<small>器材预约</small></h1>
    <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>器材管理</el-breadcrumb-item>
      <el-breadcrumb-item>器材预约</el-breadcrumb-item>
    </el-breadcrumb>
  </div>
  <div class="app-container">
    <div class="box">
      <div class="filter-container">
        <el-date-picker
                v-model="pagination.rentData"
                type="date"
                class="filter-item"
                format="yyyy 年 MM 月 dd 日"
                :picker-options="applyPickerOptions"
        ></el-date-picker>
        <el-select placeholder="请选择" v-model="pagination.rentTimeSub"  style="width: 200px;" class="filter-item">
          <el-option v-for="item in kindList" :key="item.id" :value="item.name"></el-option>
        </el-select>
        <el-button @click="findPage()" class="dalfBut">查询</el-button>

      </div>
      <el-table size="small" current-row-key="placeNo" :data="dataList" stripe highlight-current-row>
        <el-table-column type="index" align="center" label="序号"></el-table-column>
        <el-table-column prop="rentNo" label="订单编号" align="center"></el-table-column>
        <el-table-column prop="equipmentName" label="名称" align="center"></el-table-column>
        <el-table-column prop="equipmentUserID" label="租用用户" align="center"></el-table-column>
        <el-table-column prop="rent" label="租金" align="center"></el-table-column>
        <el-table-column prop="rentData" label="租用日期" align="center"></el-table-column>
        <el-table-column prop="rentTimeSub" label="租用时间段" align="center"></el-table-column>
        <el-table-column label="操作" align="center">
          <template slot-scope="scope">
            <el-button type="primary" size="mini" @click="handleFind(scope.row)">查看详情</el-button>
            <el-button size="mini" type="danger" @click="handleDelete(scope.row)">退选</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="pagination-container">
        <el-pagination
                class="pagiantion"
                @current-change="handleCurrentChange"
                :current-page="pagination.pageNow"
                :page-size="pagination.pageSize"
                layout="total, prev, pager, next, jumper"
                :total="pagination.total">
        </el-pagination>
      </div>

      <!-- 详情标签弹层 -->
      <div class="add-form">
        <el-dialog title="订单详情" :visible.sync="dialogFormVisible4Edit">
          <template>
            <el-tabs v-model="activeName" type="card">
              <el-tab-pane label="场地信息" name="first">
                <el-form label-position="right" label-width="100px">
                  <el-row>
                    <el-col :span="12">
                      <el-form-item label="器材号">
                        <el-input v-model="formData.equipmentID" :disabled="true"/>
                      </el-form-item>
                    </el-col>
                    <el-col :span="12">
                      <el-form-item label="器材名">
                        <el-input v-model="formData.equipmentName" :disabled="true"/>
                      </el-form-item>
                    </el-col>
                  </el-row>
                  <el-row>
                    <el-col :span="12">
                      <el-form-item label="租用日期">
                        <el-input v-model="formData.rentData" :disabled="true"/>
                      </el-form-item>
                    </el-col>
                    <el-col :span="12">
                      <el-form-item label="租用时间段">
                        <el-input v-model="formData.rentTimeSub" :disabled="true"/>
                      </el-form-item>
                    </el-col>
                  </el-row>
                  <el-row>
                    <el-col :span="12">
                      <el-form-item label="负责人">
                        <el-input v-model="formData.equipmenTmanager" :disabled="true"/>
                      </el-form-item>
                    </el-col>
                    <el-col :span="12">
                      <el-form-item label="租用人">
                        <el-input v-model="formData.equipmentUserName" :disabled="true"/>
                      </el-form-item>
                    </el-col>
                  </el-row>
                  <el-row>
                    <el-col :span="12">
                      <el-form-item label="租用数量" >
                        <el-input v-model="formData.rentalQuantity" :disabled="true"/>
                      </el-form-item>
                    </el-col>
                    <el-col :span="12">
                      <el-form-item label="租金（元/单位场次）" >
                        <el-input v-model="formData.rent" :disabled="true"/>
                      </el-form-item>
                    </el-col>
                  </el-row>
                  </el-row>
                  <el-row>
                    <el-col :span="24">
                      <el-form-item label="器材说明">
                        <el-input v-model="formData.description" type="textarea" :disabled="true"></el-input>
                      </el-form-item>
                    </el-col>
                  </el-row>
                </el-form>
              </el-tab-pane>
            </el-tabs>
          </template>
          <div slot="footer" class="dialog-footer">
            <el-button @click="dialogFormVisible4Edit = false">取消</el-button>
          </div>
        </el-dialog>
      </div>

    </div>
  </div>
</div>
</body>
<script>

  var vue = new Vue({
    el: '#app',

    data(){
      let that =this;
      return {
        activeName:'first',//添加/编辑窗口Tab标签名称
        pagination: {//分页相关属性
          pageNow: 1,
          pageSize:10,
          total:100,
          queryString:sessionStorage.getItem("userNo"),
          rentTimeSub:"08点-11点",
          rentData:new Date(),
        },
        dataList: [],//列表数据
        formData: {},//表单数据
        tableData:[],//新增和编辑表单中对应的检查项列表数据
        checkitemIds:[],//新增和编辑表单中检查项对应的复选框，基于双向绑定可以进行回显和数据提交
        dialogFormVisible: false,//控制添加窗口显示/隐藏
        dialogFormVisible4Edit:false,//控制编辑窗口显示/隐藏
        kindList:[{name:"08点-10点",id:"1"},{name:"10点-12点",id:2},{name:"13点-15点",id:3}
          ,{name:"15点-17点",id:4},{name:"17点-19点",id:5},{name:"19点-21点",id:6}],
        innerCondition:"",
        el:{},
        selectDate: new Date(), // 记录首次选择的时间
        applyPickerOptions: {
          disabledDate(time) {
            let timeOptionRange = that.selectDate;
            let secondNum = -(60 * 60 * 24  * 1000 * 2); // 时间跨度为7天【一年以365天的时间计算】的限制
            let secondNum2 = 60 * 60 * 24  * 1000; // 时间跨度为7天【一年以365天的时间计算】的限制
            if (timeOptionRange) {
              return time.getTime() > timeOptionRange - secondNum || time.getTime() < timeOptionRange-secondNum2;
            }
          }
        }
      }

    },
    created() {
      this.findPage();
    },
    methods: {
      // 弹出详细窗口
      handleFind(row) {
        var param = {
          equipmentID:row["equipmentID"],//查询条件
          pageNow:this.pagination.pageNow,//页码
          pageSize:this.pagination.pageSize,//每页显示的记录数
          rentData:this.pagination.rentData.getFullYear()+"-"+(this.pagination.rentData.getMonth()+1)+"-"+
                  this.pagination.rentData.getDate(),//租用日期
          rentTimeSub:this.pagination.rentTimeSub//租用时间
        };
        axios.post("<%=request.getContextPath()%>/equipment/find.do",param).then((res)=>{
          if(res.data.data.rows.length === 1){
            //弹出编辑窗口
            console.log(res.data.data.rows[0]);
            this.dialogFormVisible4Edit = true;
            //为模型数据赋值，通过VUE数据双向绑定进行信息的回显
            this.formData={};
            this.formData = res.data.data.rows[0];
            this.formData.rentData=this.pagination.rentData.getFullYear()+"-"+(this.pagination.rentData.getMonth()+1)+"-"+
                    this.pagination.rentData.getDate();//租用日期
            this.formData.rentTime=this.pagination.rentData.getFullYear()+"-"+(this.pagination.rentData.getMonth()+1)+"-"+
                    this.pagination.rentData.getDate();//租用日期
            this.formData.rentTimeSub=this.pagination.rentTimeSub;//租用时间
            this.formData.rentalQuantity = 1;//租用数量
            this.formData.equipmentDamage = "无";
            this.formData.equipmentUserName=sessionStorage.getItem("username");//租用用户
            this.formData.equipmentUserID=sessionStorage.getItem("userNo");//租用用户
          }else{
            this.$message.error("获取数据失败，请刷新当前页面");
          }
        });
      },
      //分页查询
      findPage() {
        //分页参数
        var param = {
          pageNow:this.pagination.pageNow,//页码
          pageSize:this.pagination.pageSize,//每页显示的记录数
          equipmentUserID:this.pagination.queryString,
          equipmentUserName:this.pagination.queryString,
          rentData:this.pagination.rentData.getFullYear()+"-"+(this.pagination.rentData.getMonth()+1)+"-"+
                  this.pagination.rentData.getDate(),//租用日期
          rentTimeSub:this.pagination.rentTimeSub//租用时间
        };
        //请求后台
        axios.post("<%=request.getContextPath()%>/equipmentRent/find.do",param).then((response)=> {
          //为模型数据赋值，基于VUE的双向绑定展示到页面
          this.dataList = response.data.data.rows;
          this.pagination.total =  response.data.data["totalCount"];
        });
      },
      //器材租用
      handleDelete(row) {
        this.$confirm('是否退选该器材?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          var param = {
            rentNo : row["rentNo"],
          }
          console.log(param);
          axios.post("<%=request.getContextPath()%>/equipmentRent/delete.do",param)
                  .then((response)=> {
                    if(response.data.success){
                      //新增成功，弹出成功提示
                      this.$message({
                        message: response.data.data,
                        type: 'success'
                      });
                    }else{
                      //新增失败，弹出错误提示
                      this.$message.error(response.data.mdataessage);
                    }
                  }).finally(()=> {
            this.findPage();
          });
        }).catch(() => {
          // 点击取消进行的操作
        })


      },
      // 重置表单
      resetForm() {
        this.formData = {};
      },
      //切换页码
      handleCurrentChange(pageNow) {
        //pageNow为切换后的页码
        this.pagination.pageNow = pageNow;
        this.findPage();
      },
    },

  })
</script>
</html>